package com.ruoyi.merchant.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.merchant.domain.ShopVerification;
import com.ruoyi.merchant.service.IShopVerificationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 店铺认证：存储店铺的认证信息Controller
 * 
 * @author ruoyi
 * @date 2025-09-15
 */
@RestController
@RequestMapping("/shopVerification")
public class ShopVerificationController extends BaseController
{
    @Autowired
    private IShopVerificationService shopVerificationService;

    /**
     * 查询店铺认证：存储店铺的认证信息列表
     */
    @RequiresPermissions("merchant:shopVerification:list")
    @GetMapping("/list")
    public TableDataInfo list(ShopVerification shopVerification)
    {
        startPage();
        List<ShopVerification> list = shopVerificationService.selectShopVerificationList(shopVerification);
        return getDataTable(list);
    }

    /**
     * 导出店铺认证：存储店铺的认证信息列表
     */
    @RequiresPermissions("merchant:shopVerification:export")
    @Log(title = "店铺认证：存储店铺的认证信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopVerification shopVerification)
    {
        List<ShopVerification> list = shopVerificationService.selectShopVerificationList(shopVerification);
        ExcelUtil<ShopVerification> util = new ExcelUtil<ShopVerification>(ShopVerification.class);
        util.exportExcel(response, list, "店铺认证：存储店铺的认证信息数据");
    }

    /**
     * 获取店铺认证：存储店铺的认证信息详细信息
     */
    @RequiresPermissions("merchant:shopVerification:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(shopVerificationService.selectShopVerificationById(id));
    }

    /**
     * 新增店铺认证：存储店铺的认证信息
     */
    @RequiresPermissions("merchant:shopVerification:add")
    @Log(title = "店铺认证：存储店铺的认证信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopVerification shopVerification)
    {
        return toAjax(shopVerificationService.insertShopVerification(shopVerification));
    }

    /**
     * 修改店铺认证：存储店铺的认证信息
     */
    @RequiresPermissions("merchant:shopVerification:edit")
    @Log(title = "店铺认证：存储店铺的认证信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopVerification shopVerification)
    {
        return toAjax(shopVerificationService.updateShopVerification(shopVerification));
    }

    /**
     * 删除店铺认证：存储店铺的认证信息
     */
    @RequiresPermissions("merchant:shopVerification:remove")
    @Log(title = "店铺认证：存储店铺的认证信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(shopVerificationService.deleteShopVerificationByIds(ids));
    }


    @InnerAuth
    @PostMapping("/register1")
    public Integer add1(@RequestBody ShopVerification shopVerification)
    {
        shopVerificationService.insertShopVerification(shopVerification);
        return shopVerification.getId();
    }

    @GetMapping("/byPhone")
    public AjaxResult getByPhone(HttpServletRequest request) {
        LoginUser user = SecurityUtils.getLoginUser();
        String phonenumber = user.getSysUser().getPhonenumber();
        System.out.println("商家手机号是："+phonenumber);
        return AjaxResult.success(shopVerificationService.getPhone(phonenumber));
    }
}
